package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;

/**
 * A wrapper Container for holding components that use a background Color
 * containing an alpha value with some transparency.
 * 
 * @author Matthew Adams
 * @version 1.0
 */
@SuppressWarnings("serial")
public class AlphaContainer extends JComponent {
  /**
   * Current transparency alpha level.
   */
  private static final int ALPHA_LEVEL = 150;
  /**
   * JComponent being contained.
   */
  private final JComponent my_component;
  /**
   * Default constructor set up a null component.
   */
  public AlphaContainer() {
    super();
    my_component = null;
  }
  /**
   * Creates a JComponent that shields a given JComponent from painting 
   * issues from having a background color with transparency.
   * 
   * @param the_component JComponent being contained in this container.
   */
  public AlphaContainer(final JComponent the_component) {
    super();
    my_component = the_component;
    setLayout(new BorderLayout());
    setOpaque(false);
    my_component.setOpaque(false);
    add(my_component);
  }
  /**
   * Paints the background of my_component with transparency.
   * 
   * @param the_g Graphics object used to paint.
   */
  @Override
  public void paintComponent(final Graphics the_g) {
    the_g.setColor(new Color(0, 0, 0, ALPHA_LEVEL));
    the_g.fillRect(0, 0, my_component.getWidth(), my_component.getHeight());
  }
}